using System;
using System.Data;
using System.Configuration;
using System.Web;
using Microsoft.ApplicationBlocks.Data;

namespace SMS.SportAutoService
{
    /// <summary>
    /// Summary description for SqlDataprovider
    /// </summary>
    public class SqlDataprovider
    {
        protected string Myconn;

        public SqlDataprovider()
        {
            Myconn = "Data Source=IMPACT-WEB05\\IMPACT;Initial Catalog=impFootballService;Persist Security Info=True;User ID=impact; Password=impact;";
        }

        public int getMaxConten(int commandServiceId)
        {
            return Convert.ToInt32(SqlHelper.ExecuteScalar(Myconn, "getMaxContent", commandServiceId));
        }

        public int getContentNumberFromMessage(int idMessage)
        {
            return Convert.ToInt32(SqlHelper.ExecuteScalar(Myconn, "getContentNumberFromMessage", idMessage));
        }

        public int getIdContentMaxFromMessage(int idMessage)
        {
            return Convert.ToInt32(SqlHelper.ExecuteScalar(Myconn, "getIdContentMaxFromMessage", idMessage));
        }

        public void closeMessage(int idMessage, int idContent)
        {
            SqlHelper.ExecuteNonQuery(Myconn, "closeMessage", idMessage, idContent);
        }

        public int getMessageType(int idCS)
        {
            return Convert.ToInt32(SqlHelper.ExecuteScalar(Myconn, "getMessageType", idCS).ToString());
        }

        public void createMessageContent(int messageId, int contentNumber, string messageContent, int userCreate)
        {
            SqlHelper.ExecuteNonQuery(Myconn, "createMessageContent", messageId, contentNumber, messageContent, userCreate);
        }

        public int createMessage(int commanServiceId, string service_number, string leagueCode, string homeCode, string awayCode, string mainCode, string expandCode, int leagueLevel, int userId)
        {
            return Convert.ToInt32(SqlHelper.ExecuteScalar(Myconn, "createMessage", commanServiceId, service_number, leagueCode, homeCode, awayCode, mainCode, expandCode, leagueLevel, userId));

        }

        public int getCommandServiceOption(int idCS, int optionId)
        {
            return Convert.ToInt32(SqlHelper.ExecuteScalar(Myconn, "getCommandServiceOption", idCS, optionId));
        }

        public void deleteContentMessage(int contentNumber, int idMessage)
        {
            SqlHelper.ExecuteNonQuery(Myconn, "deleteContentMessage", contentNumber, idMessage);
        }

        public IDataReader getContentList(int idMessage)
        {
            return SqlHelper.ExecuteReader(Myconn, "getContentMessage", idMessage);
        }
        
        public IDataReader getMessageByMessageId(int messageId)
        {
            return SqlHelper.ExecuteReader(Myconn, "getMessageByMessageId", messageId);
        }

        public int getUpdateCount(int idMessage)
        {
            return Convert.ToInt32(SqlHelper.ExecuteScalar(Myconn, "getUpdateCount", idMessage));
        }        

        public void updateCounter(int counter, int idMessage)
        {
            SqlHelper.ExecuteNonQuery(Myconn, "insertUpdateCount", counter, idMessage);
        }

        public object checkCloseMessage(int idMessage)
        {
            return SqlHelper.ExecuteScalar(Myconn, "checkCloseMessage", idMessage);
        }

        public void updateContentMessage(int idContent, int idMessage, string contentMessage, int userId)
        {
            SqlHelper.ExecuteNonQuery(Myconn, "updateContentMessage", idContent, idMessage, contentMessage, userId);
        }
    }
}